﻿using System;
using UnityEngine;

namespace UnityStandardAssets.ImageEffects
{
	// Token: 0x020005E2 RID: 1506
	[ExecuteInEditMode]
	[AddComponentMenu("Image Effects/Edge Detection/Edge Detection")]
	[RequireComponent(typeof(Camera))]
	public class EdgeDetection : PostEffectsBase
	{
		// Token: 0x06001DA6 RID: 7590 RVA: 0x0006AEA8 File Offset: 0x000690A8
		public override bool CheckResources()
		{
			base.CheckSupport(true);
			this.edgeDetectMaterial = base.CheckShaderAndCreateMaterial(this.edgeDetectShader, this.edgeDetectMaterial);
			if (this.mode != this.oldMode)
			{
				this.SetCameraFlag();
			}
			this.oldMode = this.mode;
			if (!this.isSupported)
			{
				base.ReportAutoDisable();
			}
			return this.isSupported;
		}

		// Token: 0x06001DA7 RID: 7591 RVA: 0x00012AEA File Offset: 0x00010CEA
		public new void Start()
		{
			this.oldMode = this.mode;
		}

		// Token: 0x06001DA8 RID: 7592 RVA: 0x0006AF10 File Offset: 0x00069110
		public void SetCameraFlag()
		{
			if (this.mode == EdgeDetection.EdgeDetectMode.SobelDepth || this.mode == EdgeDetection.EdgeDetectMode.SobelDepthThin)
			{
				base.GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
			}
			else if (this.mode == EdgeDetection.EdgeDetectMode.TriangleDepthNormals || this.mode == EdgeDetection.EdgeDetectMode.RobertsCrossDepthNormals)
			{
				base.GetComponent<Camera>().depthTextureMode |= DepthTextureMode.DepthNormals;
			}
		}

		// Token: 0x06001DA9 RID: 7593 RVA: 0x00012AF8 File Offset: 0x00010CF8
		public void OnEnable()
		{
			this.SetCameraFlag();
		}

		// Token: 0x06001DAA RID: 7594 RVA: 0x0006AF78 File Offset: 0x00069178
		[ImageEffectOpaque]
		public void OnRenderImage(RenderTexture source, RenderTexture destination)
		{
			if (!this.CheckResources())
			{
				Graphics.Blit(source, destination);
				return;
			}
			Vector2 vector = new Vector2(this.sensitivityDepth, this.sensitivityNormals);
			this.edgeDetectMaterial.SetVector("_Sensitivity", new Vector4(vector.x, vector.y, 1f, vector.y));
			this.edgeDetectMaterial.SetFloat("_BgFade", this.edgesOnly);
			this.edgeDetectMaterial.SetFloat("_SampleDistance", this.sampleDist);
			this.edgeDetectMaterial.SetVector("_BgColor", this.edgesOnlyBgColor);
			this.edgeDetectMaterial.SetFloat("_Exponent", this.edgeExp);
			this.edgeDetectMaterial.SetFloat("_Threshold", this.lumThreshold);
			Graphics.Blit(source, destination, this.edgeDetectMaterial, (int)this.mode);
		}

		// Token: 0x0400177A RID: 6010
		public EdgeDetection.EdgeDetectMode mode = EdgeDetection.EdgeDetectMode.SobelDepthThin;

		// Token: 0x0400177B RID: 6011
		public float sensitivityDepth = 1f;

		// Token: 0x0400177C RID: 6012
		public float sensitivityNormals = 1f;

		// Token: 0x0400177D RID: 6013
		public float lumThreshold = 0.2f;

		// Token: 0x0400177E RID: 6014
		public float edgeExp = 1f;

		// Token: 0x0400177F RID: 6015
		public float sampleDist = 1f;

		// Token: 0x04001780 RID: 6016
		public float edgesOnly;

		// Token: 0x04001781 RID: 6017
		public Color edgesOnlyBgColor = Color.white;

		// Token: 0x04001782 RID: 6018
		public Shader edgeDetectShader;

		// Token: 0x04001783 RID: 6019
		public Material edgeDetectMaterial;

		// Token: 0x04001784 RID: 6020
		public EdgeDetection.EdgeDetectMode oldMode = EdgeDetection.EdgeDetectMode.SobelDepthThin;

		// Token: 0x020005E3 RID: 1507
		public enum EdgeDetectMode
		{
			// Token: 0x04001786 RID: 6022
			TriangleDepthNormals,
			// Token: 0x04001787 RID: 6023
			RobertsCrossDepthNormals,
			// Token: 0x04001788 RID: 6024
			SobelDepth,
			// Token: 0x04001789 RID: 6025
			SobelDepthThin,
			// Token: 0x0400178A RID: 6026
			TriangleLuminance
		}
	}
}
